package io.kljf.boot.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

/**
 * 转换工具
 *
 * @author katherine
 * @version 2020-12-01
 **/
@Slf4j
public class ConvertUtils {
    public static <T> T sourceToTarget(Object source, Class<T> target){
        if(source == null){
            return null;
        }
        T targetObject = null;
        try {
            targetObject = target.newInstance();
            BeanUtils.copyProperties(source, targetObject);
        } catch (Exception e) {
            log.error("转换失败", e);
        }

        return targetObject;
    }
}
